<script setup>
import {ref} from 'vue';

import {useRoute, useRouter} from "vue-router";

import {useUserStore} from '@/stores/UserStores.js'
import {usePublicStore} from '@/stores/PublicStores.js'

const UserStore = useUserStore()
const PublicStore = usePublicStore()
const {uploadEmptyTable} = UserStore
const {setKeys, updateKey} = PublicStore
const route = useRoute();
const router = useRouter();
const userId = route.params.userId;
const userName = ref('');

const loading = ref(false)

// 跳转到查看课程表页面
const viewTable = () => {
  // 跳转路由
  router.push({name: 'UpdateCourseSchedule'});
}

const uploadTable = () => {
  loading.value = true
  uploadEmptyTable(userId, userName.value,
      () => {
        setKeys(userId)
        updateKey(userId)
        viewTable()
      },
      ()=> {loading.value = false})
}
</script>

<template>
  <div class="box">
    <el-form>
      <h3>创建一个空的课程表</h3>
      <p>如果上传图片时遇到了困难，<br>请尝试创建一个空的值班表，<br>然后直接手动编辑值班表</p>
      <el-input type="text" v-model="userName" placeholder="请输入自己的真实姓名"/>

      <el-button type="primary" @click="uploadTable()">创建一个空的值班表</el-button>
    </el-form>
  </div>
</template>

<style scoped>
.box {
  display: flex;
  align-items: center;
  flex-direction: column;
}
.el-form {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.el-form > * {
  margin: 5px 0;
}
</style>